#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int q[N], s[N];
int n;
int sum;

int main(void)
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &q[i]);

    int i = 1, j = 1;
    while (j <= n + 1)
    {
        if (j == n + 1 || s[q[j]])
        {
            sum = sum > j - i ? sum : j - i;
            for (int k = i; k < s[q[j]]; k++)
                s[q[k]] = 0; // 剔除
            i = s[q[j]] + 1;
        }
        s[q[j]] = j;
        j++;
    }

    cout << sum << endl;
}